package com.hc.componentspringboot.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * MybatisPlus通用字段默认处理类
 */
@Component
public class CustomMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        Date date = new Date();
        strictInsertFill(metaObject,"createdTime", Date.class,date);
        strictInsertFill(metaObject,"modifiedTime", Date.class,date);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        strictUpdateFill(metaObject,"modifiedTime",Date.class,new Date());
    }
}
